﻿Imports System.Text

Namespace DotNetNuke.Modules.ActiveForums.Controls
    Public Class ControlPanel
        Public Property PortalId() As Integer
        Public Property ModuleId() As Integer

        Sub New(ByVal _portalId As Integer, ByVal _moduleId As Integer)
            PortalId = _portalId
            ModuleId = _moduleId
        End Sub

        Public Function TemplatesOptions(ByVal templateType As Templates.TemplateTypes) As String
            Dim sb As New StringBuilder
            Dim tc As New TemplateController
            sb.Append("<option value=""0"">[RESX:Default]</option>")
            Dim lc As List(Of TemplateInfo) = tc.Template_List(PortalId, ModuleId, templateType)
            For Each l As TemplateInfo In lc
                sb.Append("<option value=""" & l.TemplateId & """>" & l.Subject & "</option>")
            Next
            Return sb.ToString
        End Function
        Public Function ForumGroupOptions() As String
            Dim sb As New StringBuilder
            sb.Append("<option value=""-1"">" & Utilities.GetSharedResource("DropDownSelect", True) & "</option>")
            Using dr As IDataReader = DataProvider.Instance.Forums_List(PortalId, ModuleId, -1, -1, False)
                Dim tmpGroupId As Integer = -1
                While dr.Read
                    If Not tmpGroupId = CInt(dr("ForumGroupId")) Then
                        sb.Append("<option value=""GROUP" & dr("ForumGroupId").ToString & """>" & dr("GroupName").ToString & "</option>")
                        tmpGroupId = CInt(dr("ForumGroupId"))
                    End If
                    If Not CInt(dr("ForumId")) = 0 Then
                        If CInt(dr("ParentForumID")) = 0 Then
                            sb.Append("<option value=""FORUM" & dr("ForumId").ToString & """> - " & dr("ForumName").ToString & "</option>")
                        End If
                    End If
                End While
                dr.Close()
            End Using

            
            Return sb.ToString
        End Function
        Public Function BindRolesForSecurityGrid(ByVal rootPath As String) As String
            Dim sb As New StringBuilder

            Dim rc As New DotNetNuke.Security.Roles.RoleController
            For Each ri As DotNetNuke.Security.Roles.RoleInfo In rc.GetPortalRoles(PortalId)
                sb.Append("<option value=""" & ri.RoleID & """>" & ri.RoleName & "</option>")
            Next
#If SKU <> "LITE" Then
            If IO.File.Exists(rootPath & "bin\active.modules.social.dll") Then
                Dim social As New Modules.ActiveForums.Social
                Using dr As IDataReader = social.ActiveSocialListGroups(PortalId)
                    While dr.Read()
                        sb.Append("<optgroup label=""" & dr("GroupName").ToString & """>")
                        sb.Append("<option value=""" & dr("GroupId").ToString & ":0"">Group Admin</option>")
                        sb.Append("<option value=""" & dr("GroupId").ToString & ":1"">Group Member</option>")
                        sb.Append("</optgroup>")

                    End While
                    dr.Close()
                End Using
            End If
#End If

            Return sb.ToString
        End Function
    End Class
End Namespace
